package com.lagou.product.controller;


import com.lagou.product.mapper.ProductMapper;
import com.lagou.product.pojo.Product;
import com.lagou.product.pojo.ProductQuery;
import com.lagou.product.pojo.ProductVo;
import com.lagou.product.pojo.ResultVo;
import com.lagou.product.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private ProductService productService;




    @PostMapping("/upload")
    public ResultVo<Object> uploadProduct(@RequestBody Product product){
        Product saveProduct = productService.saveProduct(product);

        return ResultVo.builder().code(200).data(saveProduct).build();
    }

    @PostMapping("/query")
    public ResultVo<Object> queryProduct(@RequestBody ProductQuery productQuery){
        List<ProductVo> products = productService.queryProduct(productQuery);

        return ResultVo.builder().code(200).data(products).build();
    }


}
